package com.rain.codemother.core.saver;

import com.rain.codemother.ai.model.HtmlCodeResult;
import com.rain.codemother.ai.model.MultiFileCodeResult;
import com.rain.codemother.core.parser.HtmlCodeParser;
import com.rain.codemother.core.parser.MultiFileCodeParser;
import com.rain.codemother.exception.BusinessException;
import com.rain.codemother.exception.ErrorCode;
import com.rain.codemother.model.enums.CodeGenTypeEnum;

import java.io.File;

public class CodeFileSaverExecutor {

    private static final HtmlCodeFileSaverTemplate htmlCodeFileSaverTemplate=new HtmlCodeFileSaverTemplate();
    private static final MultiCodeFileSaverTemplate multiCodeFileSaverTemplate=new MultiCodeFileSaverTemplate();

    public static File executeSaver(Object codeResult, CodeGenTypeEnum codeGenTypeEnum,Long appId){
        return switch (codeGenTypeEnum){
            case HTML->htmlCodeFileSaverTemplate.saveCode((HtmlCodeResult) codeResult,appId);
            case MULTI_FILE->multiCodeFileSaverTemplate.saveCode((MultiFileCodeResult) codeResult,appId);
            default -> throw new BusinessException(ErrorCode.PARAMS_ERROR);
        };
    }
}
